<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $table = 'users';
    protected $dateFormat = 'U';

    const UPDATED_AT = 'create_time';
    const CREATED_AT = 'update_time';

    protected $fillable = [
        'name',
        'password',
        'mobile',
        'remember_token',
        'duration',
        'age',
        'email',
        'sex',
        'education',
        'grad_school',
        'avatar',
        'self_intro',
        'duration',
        'type'
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    public function getDurationAttribute() {
        return json_decode($this->attributes['duration']);
    }

    public function getTypeAttribute() {
        return json_decode($this->attributes['type']);
    }

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    public function skill()
    {
        return $this->hasMany('App\Models\Skill', 'user_id', 'id');
    }

    public function experience()
    {
        return $this->hasMany('App\Models\Exp', 'user_id', 'id');
    }
}
